#ifndef LIB_H
#define LIB_H
#include <mmu.h>
#include <trap.h>
/////////////////////////////////////////////////////head
extern void umain();
extern void libmain();
extern void exit();


//////////////////////////////////////////////////////printf
#include <stdarg.h>
#define		LP_MAX_BUF	80

void user_lp_Print(void (*output)(void *, char *, int), 
	      void * arg,
	      char *fmt, 
	      va_list ap);

void writef(char *fmt, ...);

void _user_panic(const char *, int, const char *, ...) 
	__attribute__((noreturn));

#define user_panic(...) _user_panic(__FILE__, __LINE__, __VA_ARGS__)


/////////////////////////////////////////////////////fork

int fork(void);

void user_bcopy(const void *src, void *dst, size_t len);
void user_bzero(void *v, u_int n);
//////////////////////////////////////////////////syscall_lib
void syscall_putchar(char ch);
 u_int syscall_getenvid(void);
 void syscall_yield(void);
 void syscall_env_destroy(u_int envid);
 int syscall_set_pgfault_handler(u_int envid, u_int func, u_int xstacktop);
 int syscall_mem_alloc(u_int envid, u_int va, u_int perm);
 int syscall_mem_map(u_int srcid, u_int srcva, u_int dstid, u_int dstva, u_int perm);
 int syscall_mem_unmap(u_int envid, u_int va);
 int syscall_env_alloc(void);
 int syscall_set_env_status(u_int envid, u_int status);
 int syscall_set_trapframe(u_int envid, struct Trapframe *tf);
 void syscall_panic(char *msg);


#define user_assert(x)	\
	do {	if (!(x)) user_panic("assertion failed: %s", #x); } while (0)


#endif
